/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.perficient.ibuzz.ui;

import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.googleapis.GoogleTransport;
import com.google.api.client.googleapis.json.JsonCParser;
import com.google.api.client.http.HttpTransport;
import com.perficient.ibuzz.controller.IBuzzController;
import com.perficient.ibuzz.service.Auth;
import com.perficient.ibuzz.service.BuzzMessageReceiver;
import java.awt.Image;
import java.awt.TrayIcon;
import java.awt.image.BufferedImage;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.plaf.metal.MetalIconFactory.FileIcon16;


/**
 *
 * @author Trainning
 */

public class BuzzTrayIcon extends TrayIcon implements Runnable{
    private Image image;
    private IBuzzController controller = null;

    private boolean isEndable;

    public BuzzTrayIcon(Image image, IBuzzController contr) {
        super(image);
        this.image = image;
        this.controller = contr;
        this.isEndable = false;
    }

    public void setIsEndable(boolean isEndable) {
        this.isEndable = isEndable;
    }

    @Override
    public void run() {
        
        Image blankImage = new BufferedImage(16, 16, BufferedImage.TYPE_4BYTE_ABGR);
       // MessageReceiver receiver = new JasonMessageReceiver(setUpTransport(), "zhujiang.net@gmail.com");
        Date lastupdate = new Date();
        while(!isEndable) {
                if (controller.isOutOfDate(lastupdate)) {
                    try {
                        this.setImage(blankImage);
                        Thread.sleep(300);
                        this.setImage(image);
                        Thread.sleep(300);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(BuzzTrayIcon.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else {
                    if (!this.getImage().equals(image)) {
                        this.setImage(image);
                    }
                }
        }
    }

}
